<template>
  <div class="">
    <div :id="chartId" class="chart"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
export default {
  data() {
    return {};
  },
  props: ["chartId", "datas"],
  created(){
    this.$nextTick(()=>{
      this.$watch('datas',()=>{
        this.initChart();
      })
    })
  },
  mounted() {
    this.initChart();
  },
  methods: {
    initChart() {
      let myChart = echarts.init(document.getElementById(this.chartId));

      // 绘制图表
      myChart.setOption({
        textStyle: {
          // 全局字体样式
          color: "#fff",
          fontSize: 14,
        },
        radar: {
          // shape: 'circle',
          splitNumber: 4,
          grid: {
            top: "10%",
            left: "10%",
            right: "10%",
            bottom: "10%",
            containLabel: true,
          },
          splitArea: {
            show: false,
          },
          splitLine: {
            lineStyle: {
              color: ["RGBA(92, 251, 255, 0.3)"],
            },
          },
          axisLine: {
            lineStyle: {
              color: "RGBA(92, 251, 255, 0.3)",
            },
          },
          indicator: this.datas.indicator,
        },
        series: [
          {
            name: "雷达图",
            type: "radar",
            symbol: "circle", //none为不显示
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    {
                      offset: 0,
                      color: "RGBA(92, 251, 255, 1)",
                    },
                    {
                      offset: 1,
                      color: "RGBA(92, 251, 255, 0.1)",
                    },
                  ],
                  false
                ),
              },
            },
            itemStyle: {
              lineStyle: {
                width: 2,
              },
            },
            emphasis: {
              areaStyle: {
                opacity: 0.6,
              },
            },
            label: {
              show: true, // 显示标签
              fontSize: 14,
              color: "#fff",
            },
            data: [
              {
                value: this.datas.value,
              },
            ],
          },
        ],
      });

      window.onresize = function () {
        // 自适应大小
        myChart.resize();
      };
    },
  },
};
</script>
<style scoped lang="scss">
.chart {
  height: 260px;
}
</style>
